package com.atguigu.yygh.sms.listener;

import com.atguigu.yygh.rabbitmq.config.MQConfig;
import com.atguigu.yygh.rabbitmq.config.MQProperties;
import com.atguigu.yygh.sms.service.SmsService;
import com.atguigu.yygh.vo.msm.SmsVo;
import com.rabbitmq.client.Channel;
import io.swagger.annotations.Api;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author zhmwi
 * @Date 2021/7/22
 * @Dersciption
 */
@Component
@Api("发送短信的监听器")
public class MQSmsListener {
    @Autowired
    private SmsService smsService;

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = MQProperties.QUEUE_MSM_ITEM,durable = "true"),
                                             exchange = @Exchange(MQProperties.EXCHANGE_DIRECT_MSM),
                                              key = {MQProperties.ROUTING_MSM_ITEM}))
    public void send(SmsVo smsVo, Message message, Channel channel){
        smsService.sendMessage(smsVo);
    }
}
